<%@ page import="com.tzy.newbank.Pojo.Bankuser" %>
<%@ page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<%
    String one= (String) session.getAttribute("money");
    Bankuser user = (Bankuser) session.getAttribute("user");
    String name="无";
    if (user != null) {
        name= user.getName();
    }
    session.setAttribute("user",user);
%>
<head>
    <script>
        // 当页面加载完成后，执行此函数
        window.onload = function() {
            // 从Local Storage中获取JWT令牌
            var jwtToken = localStorage.getItem('jwt');
            // alert('JWT令牌：'+jwtToken);

            // 将JWT令牌设置到隐藏域中
            document.getElementById('jwtToken1').value = jwtToken;
            document.getElementById('jwtToken2').value = jwtToken;
            document.getElementById('jwtToken3').value = jwtToken;
            document.getElementById('jwtToken4').value = jwtToken;
        };
    </script>
    <meta charset="UTF-8">
    <title>用户管理系统</title>
    <style>

        table {
            width: 80%;
            margin: 20px auto;
            border-collapse: collapse;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
        }

        .button-container {
            margin: 20px auto;
            text-align: center;
        }

        .button-container button {
            padding: 10px;
            margin: 0 10px;
            font-size: 16px;
            cursor: pointer;
        }

/* 所有表单的通用样式 */
#addForm, #DeleteForm, #transferForm,#DestroyForm{
    display: none;
    border: 1px solid #ccc;
    padding: 20px;
    border-radius: 8px;
    background-color: #f8f8f8;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

/* 表单标签的通用样式 */
#addForm label, #DeleteForm label, #transferForm label,#DestroyForm label{
    display: block;
    margin-bottom: 8px;
}

/* 表单输入框的通用样式 */
#addForm input, #DeleteForm input, #transferForm input,#DestroyForm input{
    width: 100%;
    padding: 8px;
    margin-bottom: 12px;
    box-sizing: border-box;
}

/* 表单按钮的通用样式 */
#addForm button, #DeleteForm button, #transferForm button,#DestroyForm button {
    padding: 8px;
    background-color: #4caf50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* 鼠标悬停时按钮的颜色变化 */
#addForm button:hover, #DeleteForm button:hover, #transferForm button:hover ,#DestroyForm button:hover{
    background-color: #45a049;
}
    </style>
    <script>
        function showForm(formName) {
            disableOtherElements(true, formName);
            document.getElementById(formName).style.display = "block";
        }

        function hideForm(formName) {
            disableOtherElements(false, formName);
            document.getElementById(formName).style.display = "none";
        }

        function disableOtherElements(disable) {
            var elements = document.getElementsByClassName("dont");
            for (var i = 0; i < elements.length; i++) {
                elements[i].disabled = disable;
            }
        }
    </script>
</head>
<body>
<h2>银行管理系统 - 欢迎<%= name%>登录，现有余额<%= one%>元<br><br><br><br><br></h2>

<%-- 按钮操作区域 --%>
<div class="button-container">
    <button class="dont" onclick="showForm('addForm')">存钱</button>
    <button class="dont" onclick="showForm('DeleteForm')">取钱</button>
    <button class="dont" onclick="showForm('transferForm')">转账</button>
    <button class="dont" onclick="showForm('DestroyForm')">销毁账户</button>
    <button class="dont" onclick="location.href='index.jsp'">返回登录页面</button>
</div>
<div id="addForm">
    <form action="http://127.0.0.1:8082/update/deposit" method="post">
        <input type="hidden" id="jwtToken1" name="jwtToken">
        <label for="money">存入金额：</label>
        <input type="text" id="money" name="money" required><br>
        <button type="submit">确认</button>
        <button type="button" onclick="hideForm('addForm')">返回</button>
    </form>
</div>
<div id="DeleteForm">
    <form action="http://127.0.0.1:8082/update/withdrawals" method="post">
        <input type="hidden" id="jwtToken2" name="jwtToken">
        <label for="money2">取回金额：</label>
        <input type="text" id="money2" name="money" required><br>
        <button type="submit">确认</button>
        <button type="button" onclick="hideForm('DeleteForm')">返回</button>
    </form>
</div>
<div id="transferForm">
    <form action="http://127.0.0.1:8082/update/transfer" method="post">
        <input type="hidden" id="jwtToken3" name="jwtToken">
        <label for="money2">转账金额：</label>
        <input type="text" id="money3" name="money" required><br>
        <label for="money2">转账给用户：</label>
        <input type="text" id="user2" name="user2" required><br>
        <button type="submit">确认</button>
        <button type="button" onclick="hideForm('transferForm')">返回</button>
    </form>
</div>
<div id="DestroyForm">
    <form action="http://127.0.0.1:8082/update/destroy" method="post">
        <input type="hidden" id="jwtToken4" name="jwtToken">
        <button type="submit">确认销毁</button>
        <button type="button" onclick="hideForm('DestroyForm')">返回</button>
    </form>
</div>
</body>
</html>
